#include <cstdio>
#define M 200907

long long get_pow(long long d, int k);

int main(int argc, char const *argv[]){
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++){
        long long num_a, num_b, num_c;
        scanf("%lld%lld%lld", &num_a, &num_b, &num_c);
        int k;
        long long gap_num;
        scanf("%d", &k);
        bool arith_seque = false;
        if (num_b - num_a == num_c - num_b){
            arith_seque = true;
            gap_num = num_b - num_a;
        }
        else
            gap_num = num_b / num_a;
        long long result;
        if (arith_seque)
            //result = (num_a % M + ((k - 1) * gap_num) % M) % M; also works!
            result = ((num_a % M) + (((k - 1) % M) * (gap_num % M)) % M) % M;
        else
            result = (num_a % M * (get_pow(gap_num, k-1) % M)) % M;
        printf("%lld\n", result);
    }
    return 0;
}

long long get_pow(long long d, int k){
    long long return_num = 1;
    while (k != 0){
        if (k % 2 == 1){
            return_num *= d;
            return_num %= M; //forget '=', damn it.
        }
        k /= 2;
        d *= d;
        d %= M;
    }
    return return_num;
}
